//
//  MSMineViewController.m
//  SocietySale
//
//  Created by Mike on 16/10/25.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSMineViewController.h"
#import "MSMineTableViewController.h"

#import "MSPersonDatumViewController.h"
#import "MSMyFollowViewController.h"
#import "MSMyAttentionViewController.h"
#import "MSMytradeViewController.h"            //交易
#import "MSMyFootprintViewController.h"        //足迹
#import "MSPreferenceSetViewController.h"
#import "MSProjectRadarViewController.h"
#import "MSNotifacationViewController.h"
#import "MSCustomerMatchingVC.h"
#import "MSMemberServeViewController.h"
#import "MSCoinViewController.h"
#import "MSBillViewController.h"
#import "MSSetViewController.h"

@interface MSMineViewController ()
@property (nonatomic, strong) MSMineTableViewController *tableVC;
@property (nonatomic, strong) MSUserInfoModel *userModel;
@end

@implementation MSMineViewController

- (void)initNavigationBar{
    [super initNavigationBar];
    titleLable.text = @"我的";
}

- (void)initUI{
    self.tableVC = [[MSMineTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    self.tableVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-KNavBarHeight-KTabBarHeight);
    self.tableVC.enableRefresh = NO;
    self.tableVC.enableRequest = NO;
    self.tableVC.delegate = (id)self;
    self.tableVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.tableVC.view];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [netEngine requestMinePageWithTarget:self.VctrID hudView:self.contentView];
}

- (void)testDataFunc{
    if (!self.userModel) {
        self.userModel = [[MSUserInfoModel alloc] init];
        _userModel.headIcon = @"";
        _userModel.name = @"王振华";
        _userModel.company = @"中国有限公司";
        _userModel.position = @"总经理";
        _userModel.tracNum = @"6";
        _userModel.atentionNum = @"4";
        _userModel.footNum = @"27";
        _userModel.coinNum = @" 43";
    }
    
    NSMutableArray *memberArr = [NSMutableArray arrayWithArray:
                                 @[_userModel]
                                 ];
    
    NSMutableArray *memberArr2 = [NSMutableArray arrayWithArray:
                                  @[[DOKeyValue key:@"我跟踪的项目" value:_userModel.tracNum placeHolder:@"mine_genzong"],
                                    [DOKeyValue key:@"我关注的项目" value:_userModel.atentionNum placeHolder:@"mine_guanzhu"],
                                    [DOKeyValue key:@"我的交易" value:_userModel.tradeNum placeHolder:@"mine_jiaoyi"],
                                    [DOKeyValue key:@"我的足迹" value:_userModel.footNum placeHolder:@"mine_zuji"]]
                                  ];
    
    NSMutableArray *memberArr3 = [NSMutableArray arrayWithArray:
                                  @[[DOKeyValue key:@"订阅管理" value:@"" placeHolder:@"mine_pianhao"],
                                    [DOKeyValue key:@"项目雷达" value:@"" placeHolder:@"mine_leida"],
                                    [DOKeyValue key:@"通知" value:@"" placeHolder:@"mine_notice"],
                                    [DOKeyValue key:@"客户追踪" value:@"" placeHolder:@"mine_genzong"],
                                    [DOKeyValue key:@"会员服务" value:@"" placeHolder:@"mine_huiyuan"]]
                                  ];
    
    NSMutableArray *memberArr4 = [NSMutableArray arrayWithArray:
                                  @[[DOKeyValue key:@"江湖币" value:_userModel.coinNum placeHolder:@"mine_jianghubi"],
                                    [DOKeyValue key:@"我的账单" value:@"" placeHolder:@"mine_bill"]]
                                  ];
    
    NSMutableArray *memberArr5 = [NSMutableArray arrayWithArray:
                                  @[[DOKeyValue key:@"设置" value:@"" placeHolder:@"mine_setting"]]
                                  ];
    
    self.tableVC.dataArray = [@[memberArr,memberArr2,memberArr3,memberArr4,memberArr5] mutableCopy];
}

- (void)updateViewController:(NSNotification *)note {
    NSDictionary *responseDic = note.userInfo;
    if (responseDic[Receiver]==self.VctrID) {
        if (responseDic[@"MinePage"]!=nil){
            MSUserInfoModel *userModel = responseDic[@"MinePage"];
            _userModel = userModel;
            [self testDataFunc];
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            MSPersonDatumViewController *vc = [[MSPersonDatumViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];            
        }
    }
    if (indexPath.section == 1) {//我的
        if (indexPath.row == 0) {
            MSMyFollowViewController *vc = [[MSMyFollowViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 1) {
            MSMyAttentionViewController *vc = [[MSMyAttentionViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 2) {
            MSMytradeViewController *vc = [[MSMytradeViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 3) {
            MSMyFootprintViewController *vc = [[MSMyFootprintViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            MSPreferenceSetViewController *vc = [[MSPreferenceSetViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 1) {
            MSProjectRadarViewController *vc = [[MSProjectRadarViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 2) {
            MSNotifacationViewController *vc = [[MSNotifacationViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 3) {
            MSCustomerMatchingVC *vc = [[MSCustomerMatchingVC alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 4) {
            MSMemberServeViewController *vc = [[MSMemberServeViewController alloc] init];
            vc.memberType = MemberType_advanced;
            [rootNavigation pushViewController:vc animated:YES];
        }
    }
    if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            MSCoinViewController *vc = [[MSCoinViewController alloc] init];
            vc.coinCount = _userModel.coinNum;
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (indexPath.row == 1) {
            MSBillViewController *vc = [[MSBillViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
    }
    if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            MSSetViewController *vc = [[MSSetViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
    }
}

@end
